/****************************************************
 * Description: Entity for 用户组
 * Copyright:   Copyright (c) 2013
 * Company:     beiwaionline
 * @author      bfsu
 * @version     1.0
 * @see
	HISTORY
    *  2013-08-08 bfsu Create File
**************************************************/

package com.bfsuolframework.security.entity;

import java.util.Collection;
import java.util.HashSet;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.bfsuolframework.core.entity.Entity;
import com.bfsuolframework.core.entity.EntitySupport;

public class Group extends EntitySupport implements Entity {

    private static final long serialVersionUID = 1L;

    public Group(){}
    public Group(Long id){
        this.id = id;
    }

    private Long id;
    private String title;//名称
    private String description;//描述
    private Integer isSys;//是否系统组
    private Integer isEnabled;//是否有效
    private Collection<BaseUser> users;//用户
    private Collection<GroupRole> roles;//对应角色
    
    /**
     * @return 主键
     */
    public Long getId() {
        return id;
    }
    /**
     * @param 主键
     */
    public void setId(Long id) {
        this.id = id;
    }
    
    /**
     * @return 名称
     */
    public String getTitle() {
        return title;
    }
    
    /**
     * @param 名称
     */
    public void setTitle(String title) {
        this.title = title;
    }
    
    /**
     * @return 描述
     */
    public String getDescription() {
        return description;
    }
    
    /**
     * @param 描述
     */
    public void setDescription(String description) {
        this.description = description;
    }
    
    /**
     * @return 是否系统组
     */
    public Integer getIsSys() {
        return isSys;
    }
    
    /**
     * @param 是否系统组
     */
    public void setIsSys(Integer isSys) {
        this.isSys = isSys;
    }
    
    /**
     * @return 是否有效
     */
    public Integer getIsEnabled() {
        return isEnabled;
    }
    
    /**
     * @param 是否有效
     */
    public void setIsEnabled(Integer isEnabled) {
        this.isEnabled = isEnabled;
    }
    
    /**
     * @return 用户
     */
    public Collection<BaseUser> getUsers() {
        return users;
    }
	
    /**
     * @param 用户
     */
    public void setUsers(Collection<BaseUser> users) {
        this.users = users;
    }
	
    /**
     * @param 用户
     */
    public void addUser(BaseUser user) {
    	if(this.users == null){
    		this.users = new HashSet<BaseUser>();
    	}
        this.users.add(user);
    }
	
    /**
     * @param 用户
     */
    public void removeUser(BaseUser user) {
    	if(this.users == null){
    		return;
    	}
        this.users.remove(user);
    }
    


    public Collection<GroupRole> getRoles() {
		return roles;
	}
	public void setRoles(Collection<GroupRole> roles) {
		this.roles = roles;
	}
	
	/**
     * @param 角色
     */
    public void addRole(GroupRole groupRole) {
    	if(this.roles == null){
    		this.roles = new HashSet<GroupRole>();
    	}
        this.roles.add(groupRole);
    }
	
    /**
     * @param 角色
     */
    public void removeRole(GroupRole groupRole) {
    	if(this.roles == null){
    		return;
    	}
        this.roles.remove(groupRole);
    }
	
	public int hashCode() {
        return new HashCodeBuilder().append("Group").append(this.getId()).toHashCode();
    }

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (getClass() != obj.getClass())
            return false;
        if (!(obj instanceof Group))
            return false;
        final Group that = (Group)obj;
        return new EqualsBuilder().append(this.getId(), that.getId()).isEquals();
    }

    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).append("Group").append("ID="+this.getId()).toString();
    }

}

